/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package topcoder;

import java.util.ArrayList;
import java.util.Arrays;

/**
 *
 * @author Mohamed.Azouz
 */
public class BusinessTasks {

    public String getTask(String[] list, int n) {
        int t = n;
        int i = 0;
        int end = 0;
        ArrayList<String> newList = new ArrayList<String>(Arrays.asList(list));
        while (true) {
            for (int j = 0; j < n; j++) {
                i = i % newList.size();
                if (j != n - 1) {
                    i++;
                }
            }
            newList.remove(i);
            //list = this.createNewList(list, list.length - 1, i);
            /*for (int x = 0; x < list.length; x++) {
             System.out.print(list[x] + " ,");
             }*/
            //          System.out.println("");
//            System.out.println("HERE " + list[i] + "  " + i);
            if (newList.size() == 1) {
                return newList.get(0);
            }
        }
    }

    private String[] createNewList(String[] old, int n, int index) {
        String newList[] = new String[n];
        int j = 0;
        for (int i = 0; i < old.length; i++) {
            if (i != index) {
                newList[j++] = old[i];
            }
        }
        return newList;
    }

    public static void main(String[] args) {
        BusinessTasks bt = new BusinessTasks();
        /*String list[] = {"zlqamum", "yjsrpybmq", "tjllfea", "fxjqzznvg", "nvhekxr", "am", "skmazcey", "piklp",
         "olcqvhg", "dnpo", "bhcfc", "y", "h", "fj", "bjeoaxglt", "oafduixsz", "kmtbaxu",
         "qgcxjbfx", "my", "mlhy", "bt", "bo", "q"};*/
        // String list[] = {"a","b","c", "d"};
        String list[] = {"pwerpci", "k", "budsz", "cx", "h", "zheoihfv", "aeipe", "ewsvaqw", "ofvgcol", "kxlqvbfyb", "wqlofv", "gcwhnfhz", "a", "lv", "pltwcxoz", "yi", "nodixfm", "ujdp", "avkvju", "wplzbwdkz", "pajqlyppx", "kpigbest", "bthx", "gblg", "ivb", "zwgybnnctw", "c", "tbinyfef", "lbabny", "i", "qtzhruv", "azcbbhg", "rxkpz", "vvsr", "zvzpbkxu", "ncduwugkp", "cahiajuq", "mwckvuusha", "w"};
        int n = 10000000;
        /*String newLiString[]=bt.createNewList(list, list.length-1, 3);
         for (int i = 0; i < newLiString.length; i++) {
         System.out.println(newLiString[i]);
         }*/
        System.out.println(bt.getTask(list, n));


//        int j = 0;
//        for (int i = 0; i < 5; i++) {
//            j = (j % list.length);
//            System.out.println(list[j]);
//            j++;
//
//
//        }
    }
}
